/**
 * Created by zxh on 14-7-11.
 */

ms.UIMenZheng = ms.UILayer.extend({
    ctor: function() {
        this._super();
        this._ccsFileName = "menzheng.json";
    },

    initLayer: function() {
        var layer = cc.LayerColor.create(cc.color.GRAY);
        this.addChild(layer);
        var size = cc.director.getWinSize();

        var label = cc.LabelTTF.create("门诊", "Arial", 100);
        label.setColor(cc.color.BLACK);
        label.setPosition(cc.p(size.width * 0.5, size.height * 0.5));
        this.addChild(label);

        var fadeOut = cc.FadeOut.create(2);
        var call  = cc.CallFunc.create(function() {
            ms.UIHelper.loadWidgetFile("res/ccs/" + this._ccsFileName, this);
            ccs.actionManager.playActionByName(this._ccsFileName, "a1");
            ccs.actionManager.playActionByName(this._ccsFileName, "a2");
            this._label.y += 80;
            var delay = cc.DelayTime.create(1);
            var move = cc.MoveBy.create(0.5, cc.p(600, 0));
            this._label.setLocalZOrder(10);
            this._label.setVisible(true);
            this._label.runAction(cc.Sequence.create(delay, move));

            this.onMenAction();
        }, this);

        label.runAction(cc.Sequence.create(fadeOut, call));
        return true;

    },

    onMenAction: function() {
        var fadeOut = cc.FadeOut.create(0.2);
        var fadeIn = cc.FadeIn.create(0.2);

        var sequence = cc.Sequence.create(fadeOut, fadeIn);
        var repeat = cc.RepeatForever.create(sequence);
        this._menImage.runAction(repeat);

    },

    onMenImageTouchEnded: function() {
        cc.director.runScene(ms.createScene(ms.UIMenZheng2));
    }
});

ms.UIMenZheng2 = ms.UILayer.extend({
    ctor: function () {
        this._super();
        this._ccsFileName = "menzheng2.json";
    },

    onEnter: function() {
        this._super();
        this._progressBar1.setPercent(0);
        this._progressBar2.setPercent(0);

        //this._label1.setOpacity(0);
        //this._label2.setOpacity(0);
        this._continueButton.setVisible(false);

//        var fadeIn = cc.FadeIn.create(2);
//        this._label1.runAction(fadeIn);
//        var dealy  = cc.DelayTime.create(2);
//        var callFunc = cc.CallFunc.create(function() {
//            this._continueButton.setVisible(true);
//        }, this);
//        this._label2.runAction(cc.Sequence.create(dealy, fadeIn.clone(), callFunc));
        //var self = this;
        var progressBar = this._progressBar1;
        var time=0;
        var progress = function(dt) {
            progressBar.setPercent(progressBar.getPercent() + 2);
            if (progressBar.getPercent() === 100) {
                time += dt;
                if (time < 0.5) {
                    return;
                }

                if (progressBar === this._progressBar1) {
                    progressBar = this._progressBar2;
                } else {
                    this.unschedule(progress);
                    this._continueButton.setVisible(true);
                }
            }
        };
        this.schedule(progress);

    },

    onContinueButtonTouchEnded: function() {
        cc.director.runScene(ms.createScene(ms.UIMenZheng3));
    },
});

ms.UIMenZheng3 = ms.UILayer.extend({
    ctor: function () {
        this._super();
        this._ccsFileName = "menzheng3.json";
    },

    onContinueButtonTouchEnded: function() {
        cc.director.runScene(ms.createScene(ms.UIYaoShi));
    },
});